package ah.enum_;

import java.util.HashMap;
import java.util.Map;

public enum Color {
	RED(255, 0, 0), BLUE(0, 0, 255), BLACK(0, 0, 0), YELLOW(255, 255, 0), GREEN(
			0, 255, 0);
	
	//不能先于枚举常量
	private static final Map stringToEnum = new HashMap();
	private static final int a = 1;
	private static final int b = a + 1;//测试编译时常量
	static {
		for (Color color : values()) {
			stringToEnum.put(color.toString(), color);
		}
	}
	// 构造枚举值，比如RED(255,0,0)
	private Color(int rv, int gv, int bv) {
		this.redValue = rv;
		this.greenValue = gv;
		this.blueValue = bv;
		
		System.out.println(b);
		//stringToEnum.put(this.toString(), this);
	}

	public String toString() { // 覆盖了父类Enum的toString()
		return super.toString() + "(" + redValue + "," + greenValue + ","
				+ blueValue + ")";
	}

	private int redValue; // 自定义数据域，private为了封装。
	private int greenValue;
	private int blueValue;

	public static void main(String[] args) {
		for (Color name : Color.values()) {
			int i = name.ordinal();
			System.out.println(name);
		}
		System.out.println(Color.RED.getDeclaringClass());
	}

}